
$(function () {
    /* 获取屏幕可视宽度 */
    const windowWidth = document.documentElement.clientWidth
    const windowHeight = document.documentElement.clientHeight

    /* 页面高度 */
    $(".buycoupons_3Q").css("height", windowHeight)

    /* 标题高度 */
    $(".coupons_title").css({ "height": windowWidth * 0.1, "line-height": windowWidth * 0.1 + "px" })

    /* 底部确认支付 */
    $(".footer_confirmpay").css("height", windowWidth * 0.2)



    /* 购物券加减 */
    /* 加 */
    $("#addcoupon").on({
        touchstart: function () {
            // 改变input框的值
            let couponsNum = parseInt($("#couponsnum")[0].innerText) + 1
            $("#couponsnum")[0].innerText = couponsNum
            // 修改价格
            let parseprice = $("#price")[0].innerText
            parseprice = 39
            let price = parseInt(parseprice) * couponsNum
            $("#price")[0].innerText = price
            change()
        }
    })
    /* 减 */
    $("#subcoupon").on({
        touchstart: function () {
            let couponsNum = $("#couponsnum")[0].innerText
            if (couponsNum > 1) {
                // 改变input框的值
                couponsNum = parseInt(couponsNum) - 1
                $("#couponsnum")[0].innerText = couponsNum
                // 修改价格
                $("#price")[0].innerText = 39
                let price = parseInt($("#price")[0].innerText) * couponsNum
                $("#price")[0].innerText = price
                change()
            }
        }
    })
    /* 买五赠一 */
    // 监听input框的值改变
    let ten = true
    function change() {
        let num = $("#couponsnum")[0].innerText
        if (num >= 5) {
            $(".coupons_details_complimentary").css("display", "flex")
        } else {
            $(".coupons_details_complimentary").css("display", "none")
        }
        // console.log(num)
        if (num == 10 && ten) {
            let coupons = 3 - 1
            let html = ''
            for (i = 0; i < coupons; i++) {
                html += '<div class="coupons_details coupons_details_complimentary ten">' +
                    '<div class="coupons_left">' + '￥' + '<span>39</span>' +
                    '</div>' +
                    '<div class="coupons_center">' +
                    '<p class="cou_center_top">' +
                    '<text>全市门店通用</text>' +
                    '<img src="images/buy_coupons/message.png">' +
                    '</p>' +
                    '</div>' +
                    '</div>'
            }
            let oContent = $('.usable_coupons')
            oContent.append(html)
            /* 优惠券高度 */
            $(".ten").css({ "height": windowWidth * 0.225, "line-height": windowWidth * 0.225 + "px" })
            ten = false
        }
        if (num < 10 && !ten) {
            $(".ten").css("display", "none")
        }
    }

    /* 结算 */
    $("#pay").on({
        touchstart: function() {
            window.location.href = "confirmCouponsPay.html"
        }
    })
})